package test01;

import java.util.List;

// OpenAI适配器
public class OpenAIAdapter implements UnifiedAIService {
    private OpenAIClient openAIClient;

    public OpenAIAdapter(OpenAIClient openAIClient) {
        this.openAIClient = openAIClient;
    }

    @Override
    public String generateText(String prompt) {
        // 将统一请求转换为OpenAI特定格式
        List<Message> messages = convertToOpenAIMessages(prompt);

        // 调用原生OpenAI客户端
        ChatCompletion response = openAIClient.createChatCompletion(messages);

        // 将OpenAI响应转换为统一格式
        return response.getContent();
    }

    private List<Message> convertToOpenAIMessages(String prompt) {
        // 实现请求格式转换逻辑
        return List.of(new Message(prompt));
    }
}

